﻿// Write a program to convert binary numbers to hexadecimal numbers (directly).

using System;
using System.Collections.Generic;
using System.Text;

public class BinToHex
{
    static void Main()
    {
        Console.WriteLine(ToBin("00011111"));
    }

    private static Dictionary<string, char> hexCharToBin = new Dictionary<string, char>
        {
            { "0000" , '0'},
            { "0001" , '1'},
            { "0010" , '2'},
            { "0011" , '3'},
            { "0100" , '4'},
            { "0101" , '5'},
            { "0110" , '6'},
            { "0111" , '7'},
            { "1000" , '8'},
            { "1001" , '9'},
            { "1010" , 'a'},
            { "1011" , 'b'},
            { "1100" , 'c'},
            { "1101" , 'd'},
            { "1110" , 'e'},
            { "1111" , 'f'}
        };

    public static string ToBin(string hexNumberString)
    {
        StringBuilder binNumberString = new StringBuilder();
        for (int i = 0; i < hexNumberString.Length; i += 4)
        {
            binNumberString.Append(hexCharToBin[binNumberString.ToString().Substring(i, 4)]);
        }

        return binNumberString.ToString();
    }
}